package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.Component;
import com.zoo.diannaopeijian.mapper.ComponentMapper;
import com.zoo.diannaopeijian.service.ComponentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 配件服务实现类
 */
@Service
public class ComponentServiceImpl implements ComponentService {
    @Resource
    private ComponentMapper componentMapper;

    @Override
    public boolean addComponent(Component component) {
        if (CheckUtil.allNullBeanCheck(component)) {
            return true;
        }
        return componentMapper.insertSelective(component) == 1;
    }

    @Override
    public boolean updateComponent(Component component) {
        if (CheckUtil.allNullBeanCheck(component)) {
            return true;
        }
        return componentMapper.updateByPrimaryKeySelective(component) == 1;
    }

    @Override
    public boolean deleteComponentById(Integer componentId) {
        if (componentId == null) {
            throw new NullPointerException();
        }

        return componentMapper.deleteByPrimaryKey(componentId) == 1;
    }

    @Override
    public List<Component> getComponent(Component component) {
        return componentMapper.select(component);
    }

    @Override
    public List<Component> getComponentWithPage(Component component, Page page) {
        if (page != null) {
            page.onPage();
        }
        return getComponent(component);
    }




}
